// // Copyright (c) 2009 All Right Reserved // // vl // // 2018-12-01 // Contains ... using LargoCommon.Abstract; using LargoCommon.Interfaces; using LargoCommon.Music; using LargoPanels.Abstract; using System; using System.Linq; using System.Text; using System.Windows; using System.Windows.Media; using System.Xml.Linq; namespace LargoPanels.Editor { /// /// Interact logic for BarCell. /// public class BarCell : BaseCell { #region Constructors /// /// Initializes a new instance of the class. /// /// The given master. /// The given bar. /// ### public BarCell(EditorSpace givenMaster, IAbstractBar givenBar) : base(givenMaster) { this.Bar = givenBar; this.Point = new MusicalPoint(-1, this.Bar.BarIndex + 1); this.BarIndex = this.Bar.BarIndex; this.HarmonicStructure = new HarmonicStructure(HarmonicSystem.GetHarmonicSystem(DefaultValue.HarmonicOrder), "0,4,7"); } #endregion #region Main Properties /// Gets or sets the harmonic structure. /// The harmonic structure. public HarmonicStructure HarmonicStructure { get; set; } #endregion #region Properties /// /// Gets or sets the length. /// /// /// The length. /// public int Length { get; set; } /// /// Gets or sets a value indicating whether this instance is single. /// /// /// true if this instance is single; otherwise, false. /// [JetBrains.Annotations.UsedImplicitlyAttribute] public bool IsSingle { get; set; } /// /// Gets or sets a value indicating whether this instance has content. /// /// /// true if this instance has content; otherwise, false. /// [JetBrains.Annotations.UsedImplicitlyAttribute] public bool HasContent { get; set; } /// /// Gets or sets the bar. /// /// /// The bar. /// public IAbstractBar Bar { get; set; } #endregion #region Public methods /// /// Sets the data. /// /// The given data. /// Returns value. public bool SetData(IDataObject givenData) { if (givenData.GetData("HarmonicStructure") is HarmonicStructure harmonicStructure) { this.HarmonicStructure = harmonicStructure; if (this.Bar?.HarmonicBar != null) { this.Bar.HarmonicBar.SetStructure(this.HarmonicStructure); return true; } } if (givenData.GetData("MusicalTempo") is MusicalTempo tempo) { //// var rs = new BarStatus { TempoNumber = int.Parse(tempo.Key) }; this.Bar.TempoNumber = (int)tempo; //// int.Parse(tempo.Key); System.Console.Beep(990, 180); } return false; } /// Gets or sets the formatted text. /// The formatted text. public override FormattedText FormattedText() { var sb = new StringBuilder(); sb.AppendFormat("{0}\n", this.Bar.BarNumber); if (this.Bar.HarmonicBar != null) { var outline = this.Bar.HarmonicBar.SimpleStructuralOutline; if (outline.Length > 30) { outline = outline.Left(30) + "..."; } sb.AppendFormat("{0}\n", outline); } /* if (this.HarmonicStructure != null) { sb.AppendFormat("{0} ({1})\n", this.HarmonicStructure.Shortcut, this.HarmonicStructure.ToneSchema); } */ var ft = AbstractText.Singleton.FormatText(sb.ToString(), (int)this.Width - SeedSize.BasicMargin); return ft; } #endregion #region Copy-Paste /// /// Copies this instance. /// public override void Copy() { StringBuilder sb = new StringBuilder(); var xharmony = this.Bar.HarmonicBar.GetXElement; var item = xharmony.ToString(); sb.AppendFormat("{0};", item); Clipboard.SetText(sb.ToString()); //// Clipboard.SetDataObject(xstatus); Console.Beep(880, 180); } /// /// Pastes this instance. /// public override void Paste() { var s = Clipboard.GetText(); if (string.IsNullOrEmpty(s)) { return; } var splitArray = s.Split(';'); if (!splitArray.Any()) { return; } var item = splitArray.First(); var xharmony = XElement.Parse(item); var header = this.Master.GetMusicalHeader; HarmonicBar harmonicBar = new HarmonicBar(header, xharmony); this.Bar.SetHarmonicBar(harmonicBar); Console.Beep(990, 180); var space = this.Master as EditorSpace; space?.InvalidateVisual(); //// this.RedrawCell(false); } #endregion } }